BlueSpray - Help
© SchoonerTurtles, Inc. 2012-2015

Introduction
Contents
Getting Started
Download
Navigating
Tutorials
Scripting
Advanced
About

Introduction to JavaScript

Most JavaScript tutorials you'll find on the web and most JavaScript books show you how to program JavaScript in a browser. Programming JavaScript in BlueSpray is similar but the objects you'll be working with are the same. This tutorials provides you with an introduction to programming in JavaScript and everything here will apply to programming in BlueSpray or on the web. This is just an intro to JavaScript and we recommend searching the web for tutorials and books on JavaScript for more information.

Below are a series of turtorials on programming in JavaScriopt. We recommend going through each tutorial and then returning to the scripting in BlueSpray tutorials. Also, remember that programming should be fun!

Data Types

JavaScript supports standard data types including; Integers, Doubles, Strings, Dates, and arrays of these types. Java script also includes Boolean values that can have a value of "true" or "false". JavaScript uses "varient types" which just means that you declare all variables with "var" and then JavaScript takes care of converting the varibles to the type that is needed. This is actually the biggest differnce between JavaScript and Java and makes it very easy to start programming.

Arithmatic

A great place to start is just doing some math in JavaScript. Type the code below and see what happens when you push "run".

	var x=Math.min(0,10);
	println("x="+x);

?

Strings

Strings contain text and can be created in JavaScript or read from files or the Internet. Type the code belwo and hit "run":

	var TheStart="Hello from ";
	var TheMiddle="the moon";
	var TheEnd="we are watching you";
	var TheWholeThing=TheStart+TheMiddle+TheEnd;
	println(TheWholeThing);

The plus sign "+" will combine or "concatenate" two strings together. You were actually doing this below when you typed "x="+x. We do have a problem between "TheEnd" and "TheWHoleThing" as we forgot to add a space at the end of "TheMiddle" string. Try that now and then play with these lines of code until you are comfortable with strings.

When you add a number, or any object, to a string, it will be converted to a string for you. Try the following:

	var x=1;
	var y=1;
	var z=x+y;
	var Answer="z="+x+y;
	println("Correct="+z+" Answer="+Answer);

What happened? When you set "z" to "x+y" the computer added x and y together and then set z equal to 2. However, when you added "x" to the string "z=" in Answer, the computer converted "x" to a string and then added it to the string. Then it did the same thing with "y" giving you "11" instead of "2". This is a very common mistake in JavaScript that you'll want to watch our for. We recommend keeping all your calculations in one set of variables and then only convert them to strings when printing them out.

- searching in strings

- substring